#include<string.h>
#include <stdlib.h>
#include<stdio.h>

#define FILEIO

enum Color
  {
    BLACK,
    WHITE,
    GRAY
  };
void syslog(char *s);

typedef struct graph
{
  int number;
  Color color;
  int value;
  struct graph *next;
}graph;

graph* xalloc()
{
  graph* p = (graph*)malloc(sizeof(graph));

  if(p == NULL) 
    {
      syslog("memory alloc fail!!!");
      exit(1);
    }
  return p;
}
//return 0 means successful, return 1 means fail.
//array is the final result, N is the size of matrix
//a the matrix which is scaned from file
graph* MakeAdjacentLink(int N)
{
  int i,j;
  graph *array;
  int **a;
  graph *p,*np;
  int vertex=N;

  a = (int **)malloc(sizeof(int *)*N);
  memset(a,0,sizeof(int *)*N);
  array = (graph *)malloc(sizeof(graph)*N);
  memset(array,0,sizeof(graph)*N);

  for(i = 0;i<N;i++)
    {
      a[i] = (int *)malloc(N*sizeof(int));
      memset(a[i],0,sizeof(int)*N);
      
      for(j = 0;j<N;j++)
        {
          scanf("%d",&a[i][j]);
        }
    }

  for(i = 0;i<vertex;i++)
    {
      array[i].number = i + 1;
      array[i].color = WHITE;
      array[i].value = 0;
      array[i].next = NULL;
    }

  /*
   * if a[[i][j] != 0 , alloc a node link it into the parent node
   */
  for(i = 0;i<vertex;i++)
    {
      p = &array[i];
      for(j = 0;j<vertex;j++)
        {
          if(a[i][j] != 0)
            {
              np = xalloc();
              np -> number = j + 1;
              np -> color = WHITE;
              np -> value = 0;
              np -> next = NULL;
              p -> next = np;
              p = np;
            }
        }
    }

 return array;
}

void DumpAdjacentLink(graph* array,int vertex)
{
  int i = 0;
  graph *p;
  for(i = 0;i<vertex;i++)
    {
      p = &array[i];
      for(;p != NULL;p = p -> next) 
        {
          printf("%d",p -> number);
          printf(" -> "); 
        }
      printf("NULL\n");
    }
}

int main() 
{

#ifdef FILEIO
  freopen("in.txt","r",stdin); 
  freopen("out.txt","w",stdout); 
#endif
  
  int i,j; //for loop
  int N;
  int vertex;
  graph *array;
  graph *p,*np;

  scanf("%d",&N);
  vertex = N;

  array = MakeAdjacentLink(N);

  DumpAdjacentLink(array,N);

  free(array);

#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif
  return 0; 
} 


void syslog(char *s)
{
  
}

  //   int a[vertex][vertex]={
  //     {0,1,0,0,1},
  //     {1,0,1,1,1},
  //     {0,1,0,1,0},
  //     {0,1,1,0,1},
  //     {1,1,0,1,0}
  //   };
